<!-- Modal -->
<div class="modal fade " id="addFocusProModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document" style="width: 50%">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">新增关注项目</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal">
                <div class="box-body">
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">项目：</label>
                        <div class="col-sm-5">
                            <input type="hidden" id="addFocusProModal_id" >
                            <select class="form-control select2" style="width: 100%;" id="addFocusProModal_productId">

                            </select>
                        </div>
                        <button id="changeEnterTypeBtn" type="button" class="btn btn-primary"
                                onclick="addFocusProModal_changeEnterType()">切换
                        </button>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">项目名称：</label>
                        <div class="col-sm-5">
                            <input id="addFocusProModal_productName" type="text" class="form-control"
                                   disabled="disabled">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label">期限（年）：</label>
                        <div class="col-sm-3">
                            <input id="addFocusProModal_timelimit" type="text" class="form-control"  >
                        </div>
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">收益率（%）：</label>
                        <div class="col-sm-4">
                            <input id="addFocusProModal_yield" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">拟投资规模：</label>
                        <div class="col-sm-3">
                            <input id="addFocusProModal_investScale" type="text" class="form-control">
                        </div>
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">目前进展：</label>
                        <div class="col-sm-4">
                            <input id="addFocusProModal_remark" type="text" class="form-control">
                        </div>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button id="btnSubmit" type="button" class="btn btn-primary pull-right"
                                onclick="addFocusProModal_save()">保存
                        </button>
                    </div>
                    <!-- /.box-footer -->
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    function addFocusProModal_changeEnterType() {
        var type = $("#addFocusProModal_productName").attr("disabled");
        if (undefined == type) {
            $("#addFocusProModal_productId").removeAttr("disabled");
            $("#addFocusProModal_productName").val("");
            $("#addFocusProModal_productName").attr("disabled", "disabled");
        } else {
            $("#addFocusProModal_productId").select2("val","");
            $("#addFocusProModal_productId").attr("disabled", "disabled");
            $("#addFocusProModal_productName").removeAttr("disabled");
        }
    }

    function addFocusProModal_init() {
        $("#addFocusProModal_productId").empty();
        $("#addFocusProModal_productId").removeAttr("disabled");
        $("#addFocusProModal_productName").val("");
        $("#addFocusProModal_productName").attr("disabled", "disabled");
        $("#addFocusProModal_timelimit").val("");
        $("#addFocusProModal_yield").val("");
        $("#addFocusProModal_investScale").val("");
        $("#addFocusProModal_remark").val("");
        $("#addFocusProModal_id").val("");
    }

    function addFocusProModal_setValue(index) {
        var url = "/productinvest/product/list" ;
        if (index == "-1") {
            setFormValue(url,"addFocusProModal_productId") ;
        } else {
            var options = $("#table2").bootstrapTable("getData");
            var row = options[index];
            $("#addFocusProModal_timelimit").val(row.timelimit);
            $("#addFocusProModal_yield").val(row.yield);
            $("#addFocusProModal_investScale").val(row.investScale);
            $("#addFocusProModal_remark").val(row.remark);
            $("#addFocusProModal_id").val(row.id);
            setFormValue(url,"addFocusProModal_productId",row.productId) ;
        }
    }


    function addFocusProModal_save() {
        var productId = $("#addFocusProModal_productId").val();
        if(productId == "请选择" ){
            productId = "" ;
        }
        var productName = $("#addFocusProModal_productName").val();
        if ((productId == "" || undefined == productId||"请选择" == productId) && (productName == "" || undefined == productName)) {
            toastr['error']('请输入项目', '提示');
            return;
        }
        var data = {
            productId: productId,
            productName: productName,
            timelimit: $("#addFocusProModal_timelimit").val(),
            yield: $("#addFocusProModal_yield").val(),
            investScale: $("#addFocusProModal_investScale").val(),
            remark: $("#addFocusProModal_remark").val(),
            institutionId:table2QueryParams().institutionId,
            investType:"1",
            id:$("#addFocusProModal_id").val()
        };
        var url = "/productinvest/save";
        postReq(url, data, function (result) {
            if (result.success) {
                toastr['success']('操作成功', '提示');
                $("#table2").bootstrapTable("refresh");
                $("#addFocusProModal").modal("hide");
            } else {
                toastr['error'](result.msg, '提示');
            }
        });
    }
</script>
